*ed by LW on 6/18/19 to recode placebo high-income analysis. annotated 

global data /projects/mortality/data/
global userdata /projects/mortality/data/
global output /projects/mortality/output/

global controls black white hispanic female i.age


use $data/panelfinal, clear

drop if age2014 < 55

**Triple Difference with Older Ages as control group

gen under65=0
replace under65=1 if age2014 < 65

forval n=1/4{
gen eventnotold`n'=under65*event`n'
}

forval n=1/5{
gen eventnotoldm`n'=under65*eventm`n'
}

gen target1b=0
replace target1b=1 if povpi < 139
replace target1b=1 if schl < 16
replace target1b=0 if age2014 < 55
replace target1b=0 if ssi > 0
replace target1b=0 if cit=="5"
replace target1b=1 if age2014 > 64

egen styr=group(st dyear)
egen u65year=group(under65 dyear)
egen u65st=group(st under65)

keep if target1b==1

cap noi reghdfe diedpanel eventnotold4 eventnotold3 eventnotold2 eventnotold1 eventnotoldm1 eventnotoldm2 eventnotoldm3 eventnotoldm4 eventnotoldm5 sameyear under65 [pweight=pwgt] if target1b==1 & age2014 > 54, absorb(st dyear year styr u65year u65st) cluster(st)
outreg2 using $output/triplediff.xls, ctitle("DDD-All Age 65+ As Controls") append 

cap noi reghdfe diedpanel posttreatedunder65 posttreated sameyear under65 [pweight=pwgt] if target1b==1 & age2014 > 54, absorb(st dyear year styr u65year u65st) cluster(st)
outreg2 using $output/triplediff.xls, ctitle("DDD-All Age 65+ As Controls") append 

**Within treated states diff diff - 400%+ FPL as control group

use $data/panelfinal, clear

drop if age2014 < 55

gen under138=0
replace under138=1 if povpi < 139 & povpi!=.
replace under138=1 if schl < 16

forval n=1/4{
gen eventpoor`n'=under138*event`n'
}

forval n=1/5{
gen eventpoorm`n'=under138*eventm`n'
}

gen target1c=0
replace target1c=1 if povpi < 139
replace target1c=1 if povpi > 399 & povpi!=.
replace target1c=1 if schl < 16
replace target1c=0 if age2014 < 55
replace target1c=0 if age2014 > 64
replace target1c=0 if ssi > 0
replace target1c=0 if cit=="5"

gen posttreatedpoor=posttreated
replace posttreatedpoor=0 if under138==0

cap noi reghdfe diedpanel eventpoor4 eventpoor3 eventpoor2 eventpoor1 eventpoorm1 eventpoorm2 eventpoorm3 eventpoorm4 eventpoorm5 sameyear under138 under138##st under138##dyear st##dyear [pweight=pwgt] if target1c==1 & age2014 > 54 & age2014 < 65, absorb(st dyear year) cluster(st)
outreg2 using $output/triplediff.xls, ctitle("DDD-400%FPL As Controls") append 

cap noi reghdfe diedpanel posttreatedpoor sameyear under138 under138##st under138##dyear st##dyear [pweight=pwgt] if target1c==1 & age2014 > 54  & age2014 < 65, absorb(st dyear year) cluster(st)
outreg2 using $output/triplediff.xls, ctitle("DDD-400%FPL As Controls") append 


**First stage

use $data/mcaidfinalfinal, clear

replace days2=. if dyear==2017
replace cumdays=. if st==22 & dyear==2015

drop if age2014 < 55

**Triple Difference with Older Ages as control group

gen under65=0
replace under65=1 if age2014 < 65

forval n=1/4{
gen eventnotold`n'=under65*event`n'
}

forval n=1/5{
gen eventnotoldm`n'=under65*eventm`n'
}

gen target1b=0
replace target1b=1 if povpi < 139
replace target1b=1 if schl < 16
replace target1b=0 if age2014 < 55
replace target1b=0 if ssi > 0
replace target1b=0 if cit=="5"
replace target1b=1 if age2014 > 64

drop if age2014==.

egen styr=group(st dyear)
egen u65year=group(under65 dyear)
egen u65st=group(st under65)

keep if target1b==1
gen posttreatedunder65=posttreated*under65

foreach y in anymcaid days2 cumdays {
cap noi reghdfe `y' eventnotold4 eventnotold3 eventnotold2 eventnotold1 eventnotoldm1 eventnotoldm2 eventnotoldm3 eventnotoldm4 eventnotoldm5 under65 [pweight=pwgt] if target1b==1 & age2014 > 54, absorb(st dyear year styr u65year u65st) cluster(st)
outreg2 using $output/triplediff.xls, ctitle("`x'", "DDD-All Age 65+ As Controls") append 

cap noi reghdfe `y' posttreatedunder65 posttreated under65 [pweight=pwgt] if target1b==1 & age2014 > 54, absorb(st dyear year styr u65year u65st) cluster(st)
outreg2 using $output/triplediff.xls, ctitle("`x'", "DDD-All Age 65+ As Controls") append 
}


use $data/mcaidfinalfinal, clear

replace days2=. if dyear==2017

drop if age2014 < 55
replace cumdays=. if st==22 & dyear==2015


**Within treated states diff diff - 400%+ FPL as control group

gen under138=0
replace under138=1 if povpi < 139 & povpi!=.
replace under138=1 if schl < 16

forval n=1/4{
gen eventpoor`n'=under138*event`n'
}

forval n=1/5{
gen eventpoorm`n'=under138*eventm`n'
}

gen target1c=0
replace target1c=1 if povpi < 139
replace target1c=1 if povpi > 399 & povpi!=.
replace target1c=1 if schl < 16
replace target1c=0 if age2014 < 55
replace target1c=0 if age2014 > 64
replace target1c=0 if ssi > 0
replace target1c=0 if cit=="5"

gen posttreatedpoor=posttreated
replace posttreatedpoor=0 if under138==0

egen pooryear=group(under138 dyear)
egen poorst=group(st under138)
egen styr=group(st dyear)

*foreach y in anymcaid days2 cumdays {

foreach y in anymcaid days2 cumdays {
cap noi reghdfe `y' eventpoor4 eventpoor3 eventpoor2 eventpoor1 eventpoorm1 eventpoorm2 eventpoorm3 eventpoorm4 eventpoorm5 under138 [pweight=pwgt] if target1c==1 & age2014 > 54 & age2014 < 65, absorb(st dyear year styr pooryear poorst) cluster(st)
outreg2 using $output/triplediff.xls, ctitle("DDD-400%FPL As Controls") append 

cap noi reghdfe `y' posttreatedpoor under138 [pweight=pwgt] if target1c==1 & age2014 > 54  & age2014 < 65, absorb(st dyear year styr pooryear poorst) cluster(st)
outreg2 using $output/triplediff.xls, ctitle("DDD-400%FPL As Controls") append 
}
